package cn.b.sky.mes.cm.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.b.sky.mes.cm.dao.WorkCenterTypeDao;
import cn.b.sky.mes.cm.model.WorkCenterType;
import cn.b.sky.mes.cm.service.WorkCenterTypeService;
import cn.b.sky.common.exception.ImeException;
import cn.b.sky.common.model.TreeInterface;
import cn.b.sky.common.utils.TreeUtil;

/**
 * 
 * <strong>Title : WorkCenterTypeServiceImpl.java<br></strong>
 * <strong>Package : cn.b.sky.mes.cm.service.impl<br></strong>
 * <strong>Description : </strong>工作中心类型业务实现类<br> 
 * <strong>Create on : 2015-9-24 下午02:12:56<br></strong>
 * <p>
 * @author zhaoxin01<br>
 * @version <strong>v1.0.0</strong><br>
 * <br>
 * <strong>修改历史:</strong><br>
 * 修改人 | 修改日期 | 修改描述<br>
 * -------------------------------------------<br>
 * <br>
 * <br>
 */
@Service("workCenterTypeService")
public class WorkCenterTypeServiceImpl implements WorkCenterTypeService {
  @Resource
  WorkCenterTypeDao workCenterTypeDao;

  @Override
  public List<TreeInterface> selectAllWorkCenterType(String siteCode) {
    List<WorkCenterType> types = workCenterTypeDao.selectAllWorkCenterType(siteCode);
    return TreeUtil.gradingRecursion(types.toArray(new WorkCenterType[types.size()]), null);
  }

  @Override
  public WorkCenterType selectWorkCenterType(String siteCode, String workCenterTypeCode) {
    return workCenterTypeDao.selectWorkCenterType(siteCode, workCenterTypeCode);
  }

  @Override
  public void insertWorkCenterType(WorkCenterType workCenterType) {
    workCenterTypeDao.insertWorkCenterType(workCenterType);

  }

  @Override
  public void updateWorkCenterType(WorkCenterType workCenterType) {
    workCenterTypeDao.updateWorkCenterType(workCenterType);

  }

  @Override
  public void deleteWorkCenterType(String siteCode, String workCenterTypeCode) {
    if (workCenterTypeDao.selectWorkCenterTypeCountInProcess(siteCode, workCenterTypeCode) > 0) {
      throw ImeException.newException("workCenterTypeDelError.M");
    } else if (workCenterTypeDao.selectWorkCenterTypeCountInWorkCenter(siteCode, workCenterTypeCode) > 0) {
      throw ImeException.newException("workCenterTypeDelError.M");
    }
    workCenterTypeDao.deleteWorkCenterType(siteCode, workCenterTypeCode);
  }

}
